package edu.uc.labs.MobilePrinting.Daemon;

import org.tanukisoftware.wrapper.WrapperListener;
import org.tanukisoftware.wrapper.WrapperManager;

public class DaemonLoader implements WrapperListener{

	public MobilePrintListener listen;
	
	@Override
	public void controlEvent(int event) {
		if ( (event == WrapperManager.WRAPPER_CTRL_LOGOFF_EVENT) && 
				( WrapperManager.isLaunchedAsService() || WrapperManager.isIgnoreUserLogoffs() )) {
			//Ignore
		}
		
		if ( (event == WrapperManager.WRAPPER_CTRL_C_EVENT) && !WrapperManager.isLaunchedAsService()){
			WrapperManager.stop(0);
		}
	}

	@Override
	public Integer start(String[] arg0) {
		listen = new MobilePrintListener();
		listen.start();
		return null;
	}

	@Override
	public int stop(int arg0) {
		listen.halt();
		return 0;
	}
	
	/**
	 * Main Method (entry point)
	 * @param args the command line arguments
	 */
	public static void main(String[] args) {
		// Start the application.  If the JVM was launched from the native
        //  Wrapper then the application will wait for the native Wrapper to
        //  call the application's start method.  Otherwise the start method
        //  will be called immediately.
        WrapperManager.start( new DaemonLoader(), args );
	}


}
